﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using eschoolBO;

namespace ESCHOOL.admin
{
    public partial class WebForm12 : System.Web.UI.Page
    {
        album al = new album();
        protected void Page_Load(object sender, EventArgs e)
        {
            btnupdate.Visible = false;
            if (!IsPostBack)
            {
                DataTable dt = al.GetRecords(-99, "", "", false, " and ");
                GridView1.DataSource = dt;
                GridView1.DataBind();
            }
        }

        protected void btninsert_Click(object sender, EventArgs e)
        {
            al.album_id = -99;
            al.album_name = tbalbumname.Text;
            if(fufront.HasFile)
                fufront.PostedFile.SaveAs(Server.MapPath("~/admin/front/"+fufront.FileName));
            al.front_picture=fufront.FileName;
            al.isdeleted=false;
            al.SaveRecords();
            Response.Redirect("~/admin/Album.aspx");
        }

        protected void btnupdate_Click(object sender, EventArgs e)
        {
            al.album_id = Convert.ToInt64(tbalbum_id.Text);
            al.album_name = tbalbumname.Text;
            if (fufront.HasFile)
            {
                fufront.PostedFile.SaveAs(Server.MapPath("~/admin/front/" + fufront.FileName));
                al.front_picture = fufront.FileName;
            }
            else
                al.front_picture = hiddenfront.Text;
            al.isdeleted = false;
            al.SaveRecords();
            Response.Redirect("~/admin/Album.aspx");
        }


        protected void btnedit_Command1(object sender, CommandEventArgs e)
        {
            btnupdate.Visible = true;
            btninsert.Visible = false;
            DataTable dt = al.GetRecords(Convert.ToInt64(e.CommandArgument), "", "", false, " and ");
            tbalbum_id.Text = dt.Rows[0]["album_id"].ToString();
            tbalbumname.Text = dt.Rows[0]["album_name"].ToString();
            hiddenfront.Text= dt.Rows[0]["front_picture"].ToString();

        }

        protected void btndelete_Command(object sender, CommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                DataTable dt = al.GetRecords(Convert.ToInt16(e.CommandArgument), "", "", false, " and ");
                al.album_id = Convert.ToInt64(dt.Rows[0]["album_id"].ToString());
                al.album_name = dt.Rows[0]["album_name"].ToString();
                al.front_picture = dt.Rows[0]["front_picture"].ToString();
                al.isdeleted = true;
                al.SaveRecords();
                Response.Redirect("~/admin/Album.aspx");
            }
        }

        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {

        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {

        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {

        }
    }
}
